﻿using System.Collections.Generic;

using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace xEngine.Debugging
{
    public class OSD
    {
        #region Singleton

        private static OSD inst = new OSD();
        private OSD()
        {
            _list = new Dictionary<string, object>();
        }

        #endregion

        #region Member Variables

        private Dictionary<string, object> _list;
        private SpriteBatch _batch;

        #endregion

        #region Properties

        private static SpriteBatch SpriteBatch
        {
            get
            {
                if (inst._batch == null)
                    inst._batch = new SpriteBatch(Rendering.RenderManager.Device);

                return inst._batch;
            }
        }

        #endregion

        #region Functions

        public static void Add(string label, object value)
        {
            if (inst._list.ContainsKey(label))
                inst._list[label] = value;
            else
                inst._list.Add(label, value);
        }
        public static void Render()
        {
            Render(GenericResources.Fonts.Fixed08, Color.White);
        }
        public static void Render(SpriteFont font, Color color)
        {
            if (font == null || color == null)
                return;

            SpriteBatch.Begin();

            int index = 0;
            foreach (var pair in inst._list)
                SpriteBatch.DrawString(font, pair.Key + ": " + (pair.Value == null ? "NULL" : pair.Value.ToString()), new Vector2(3, index++ * font.LineSpacing + 3), color);

            SpriteBatch.End();
        }

        #endregion
    }
}
